<template>
  <a-drawer
    :title="title"
    width="50%"
    :visible="visible"
    :confirmLoading="loading"
    @close="
      () => {
        this.visible = false
        this.queryParam = { Condition: 'Customer' }
      }
    "
  >
    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="10">
          <a-col :md="7" :sm="24">
            <a-form-item label="查询类别">
              <a-select allowClear v-model="queryParam.Condition">
                <a-select-option key="CustomerId">客户编号</a-select-option>
                <a-select-option key="Customer">客户名称</a-select-option>
                <!-- <a-select-option key="cCusAddres">客户地址</a-select-option> -->
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="24">
            <a-form-item>
              <a-input v-model="queryParam.keyword" placeholder="关键字" @keydown.enter="getDataList" />
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="24">
            <a-button
              type="primary"
              @click="
                () => {
                  this.pagination.current = 1
                  this.getDataList()
                }
              "
            >查询
            </a-button>
            <a-button
              style="margin-left: 8px"
              @click="
                queryParam = { Condition: 'Customer' }
                getDataList()
              "
            >重置
            </a-button>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <a-table
      ref="table"
      :scroll="{ y: tableHeight }"
      :columns="columns"
      :rowKey="(row) => row.CustomerId"
      :dataSource="data"
      :pagination="pagination"
      :loading="loading"
      @change="handleTableChange"
      :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange, type: 'radio',columnWidth:60 }"
      :bordered="true"
      size="small"
    >
      <span slot="CreateTime" slot-scope="CreateTime">{{ timeFormat(CreateTime, 'YYYY-MM-DD') }}</span>
    </a-table>
    <!-- <OutboundDetails  :back="back" ref="OutboundDetails" :parentObj="this"></OutboundDetails> -->
    <div
      :style="{
        position: 'absolute',
        right: 0,
        bottom: 0,
        width: '100%',
        borderTop: '1px solid #e9e9e9',
        padding: '10px 16px',
        background: '#fff',
        textAlign: 'right',
        zIndex: 1,
      }"
    >
      <a-button
        :style="{ marginRight: '8px' }"
        @click="
          () => {
            this.visible = false
            this.queryParam = { Condition: 'Customer' }
          }
        "
      >取消</a-button
      >

      <a-button type="primary" @click="handleSubmit">下一步</a-button>
    </div>
  </a-drawer>
</template>

<script>
// import OutboundDetails from './OutboundDetails'
const columns = [
  { title: '客户编号', dataIndex: 'CustomerId', width: '20%', align: 'center' },
  { title: '客户名称', dataIndex: 'Customer' }
  // { title: '客户地址', dataIndex: 'cCusAddres', width: '30%' }
]
export default {
  components: {
    // OutboundDetails
  },
  props: {
    parentObj: Object
  },
  data () {
    return {
      data: [],
      selectedRowKeys: [],
      selectedRows: [],
      layout: {
        labelCol: { span: 5 },
        wrapperCol: { span: 18 }
      },
      pagination: {
        current: 1,
        pageSize: 20,
        onShowSizeChange: (current, pageSize) => (this.pageSize = pageSize),
        showTotal: (total, range) => `总数:${total} 当前:${range[0]}-${range[1]}`,
        pageSizeOptions: ['20', '30', '40', '50', '100'], // 设置pageSize的可选值，页面可以通过下拉框进行选择
        showSizeChanger: true
      },
      sorter: { field: 'Id', order: 'desc' },
      columns,
      queryParam: {
        Condition: 'Customer'
      },
      visible: false,
      loading: false,
      rules: {},
      title: '',
      tableHeight: 0
    }
  },
  mounted () {

  },
  methods: {
    openForm (id, title) {
      this.selectedRowKeys = []
      this.selectedRows = []
      this.pagination.current = 1
      this.title = title
      this.visible = true

      this.$nextTick(() => {
      // 页面渲染完成后的回调
        this.tableHeight = this.getTableHeight(true) + 24
        this.getDataList()
      })
    },
    back () {
      this.visible = true
    },
    handleTableChange (pagination, filters, sorter) {
      this.pagination = { ...pagination }
      this.filters = { ...filters }
      this.sorter = { ...sorter }
      this.getDataList()
    },
    onSelectChange (selectedRowKeys, selectedRows) {
      this.selectedRowKeys = selectedRowKeys
      this.selectedRows = selectedRows
    },
    getDataList () {
      this.selectedRowKeys = []
      this.loading = true
      this.$http
        .post('/InvoiceManagement/ST_RDRecord/GetCustomerList', {
          //PageIndex: this.pagination.current,
          //PageRows: this.pagination.pageSize,
          PageIndex: 1,
          PageRows: 10000,
          Search: this.queryParam

        })
        .then((resJson) => {
          this.loading = false
          this.data = resJson.Data
          if (this.data) {
            const pagination = { ...this.pagination }
            pagination.total = resJson.Total
            this.pagination = pagination
          }
        })
    },
    // 提交下一步
    handleSubmit () {
      if (this.selectedRowKeys.length > 0) {
        this.visible = false
        this.queryParam = { Condition: 'Customer' }
        localStorage.removeItem('SELECT_CHECK')
        // console.log()
        this.$forceUpdate()
        this.parentObj.$refs.OutboundDetails.openForm(
          this.selectedRows[0].CustomerId,
          this.selectedRows[0].Customer,
          '选择出库单',
          this.selectedRows[0]
        )
      } else {
        this.$message.warning('请选择客户')
      }
    }
  }
}
</script>
